<%@page import="weaver.hrm.User"%>
<%@page import="weaver.systeminfo.SystemEnv"%>
<%@page import="weaver.hrm.HrmUserVarify"%>
<%@page import="weaver.general.Util"%>
<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
User user = HrmUserVarify.getUser (request , response) ;
if(user==null){
	response.sendRedirect(weaver.general.GCONST.getContextPath()+"/notice/noright.jsp") ;
	return ;
}
int requestid = Util.getIntValue(request.getParameter("requestid"),0);
int workflowid = Util.getIntValue(request.getParameter("workflowid"),0);
int formid = Util.getIntValue(request.getParameter("formid"),0);
int nodeid = Util.getIntValue(request.getParameter("nodeid"),0);

%>
<script language="javascript">

jQuery().ready(function(){

	var ycsjrq = WfForm.convertFieldNameToId("ycsjrq");
	var ycsjsj = WfForm.convertFieldNameToId("ycsjsj");
	var ycsjjsrq = WfForm.convertFieldNameToId("ycsjjsrq");
	var ycsjjssj = WfForm.convertFieldNameToId("ycsjjssj");
	var carId = WfForm.convertFieldNameToId("carId");
	WfForm.bindFieldChangeEvent(ycsjrq+","+ycsjsj+","+ycsjjsrq+","+ycsjjssj+","+carId+",", function(obj,id,value){
		var ycsjrqvalue = WfForm.getFieldValue(ycsjrq);
		var ycsjsjvalue = WfForm.getFieldValue(ycsjsj);
		var ycsjjsrqvalue = WfForm.getFieldValue(ycsjjsrq);
		var ycsjjssjvalue = WfForm.getFieldValue(ycsjjssj);
		var carIdvalue = WfForm.getFieldValue(carId);
		if(ycsjrqvalue !="" && ycsjsjvalue !="" && ycsjjsrqvalue !="" && ycsjjssjvalue !="" && carIdvalue !=""){
			var status = checkCarSubmit(<%=workflowid%>,<%=formid%>,<%=nodeid%>);
			if(!status){
				WfForm.changeFieldValue(carId,{value:''});
			}
		}
	});

});


function checkCarSubmit(workflowid,formId,nodeid){
	var flag = false;
	jQuery.ajax({
	    type:"get",
		url: "<%=weaver.general.GCONST.getContextPath()%>/cpt/car/CarSetDataOperation2.jsp?action=getDataSys&time="+new Date().getTime(),
		data: {workflowid:workflowid,formId:formId},
		async: false, 
		dataType: "json",
		success: function(returndata){
			if(returndata&&returndata.length>0){
				var iscontinue = returndata[0].iscontinue;
				var remindtype = returndata[0].remindtype; 
				var requirednode = returndata[0].requirednode;
				if(requirednode!=""&&(','+requirednode+",").indexOf(","+nodeid+",")>-1){//该节点要做必填验证
					var carid = returndata[0].carid; //车辆
					var caruserid = returndata[0].caruserid; //用车人
					var startDate = returndata[0].startDate; //开始日期
					var startTime = returndata[0].startTime; //开始时间
					var endDate = returndata[0].endDate; //结束日期
					var endTime = returndata[0].endTime; //结束时间
					carid = jQuery("#field"+carid).val();
					caruserid = jQuery("#field"+caruserid).val();
					startDate = jQuery("#field"+startDate).val();
					startTime = jQuery("#field"+startTime).val();
					endDate = jQuery("#field"+endDate).val();
					endTime = jQuery("#field"+endTime).val();
					var name='';
					var mustflag=false;
					if(carid==''){
						name=returndata[0].caridname
					}else if(caruserid==''){
						name=returndata[0].caruseridname
					}else if(startDate==''){
						name=returndata[0].startDatename
					}else if(startTime==''){
						name=returndata[0].startTimename
					}else if(endDate==''){
						name=returndata[0].endDatename
					}else if(endTime==''){
						name=returndata[0].endTimename
					}else{
						mustflag=true;
					}
					if(!mustflag){
						alert(name+"<%=SystemEnv.getHtmlLabelName(18622,user.getLanguage())%>");
						flag = false;
						return ;
					}
				}
				if(iscontinue=='yes'){
					var carid = returndata[0].carid; //车辆
					var driver = returndata[0].driver; //司机
					var caruserid = returndata[0].caruserid; //用车人
					var startDate = returndata[0].startDate; //开始日期
					var startTime = returndata[0].startTime; //开始时间
					var endDate = returndata[0].endDate; //结束日期
					var endTime = returndata[0].endTime; //结束时间
					carid = jQuery("#field"+carid).val();
					startDate = jQuery("#field"+startDate).val();
					startTime = jQuery("#field"+startTime).val();
					endDate = jQuery("#field"+endDate).val();
					endTime = jQuery("#field"+endTime).val();
					jQuery.ajax({
					    type:"get",
						url: "<%=weaver.general.GCONST.getContextPath()%>/cpt/car/CarSetDataOperation2.jsp?action=checkData",
						data: {carid:carid,startDate:startDate,startTime:startTime,endDate:endDate,endTime:endTime,workflowid:workflowid,requestid:<%=requestid%>,time:new Date().getTime()},
						async: false, 
						dataType: "json",
						success: function(returnjson){
							if(returnjson&&returnjson.length>0){
								iscontinue = returnjson[0].iscontinue;
								if(iscontinue=="no"){
									if(remindtype=="0"){ 
									    if(confirm("<%=SystemEnv.getHtmlLabelName(128307,user.getLanguage())%>")==true){
									        flag = true;
									    }else{
									        flag = false;
									    }
									}else{
										alert("<%=SystemEnv.getHtmlLabelName(128308,user.getLanguage())%>");
										flag = false;
									}
								}else{
									flag = true;
								}
							}
						}
					});
				}else{
					flag = true;
				}
			}
		}
	});
	return flag;
}

</script>